import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.dreamwork.gson.GsonHelper;
import sample.data.Gender;
import sample.data.Person;
import sample.data.Product;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: seth.yang
 * Date: 14-11-27
 * Time: 上午11:31
 */
public class APITest {
    public static void main (String[] args) throws Exception {
        Gson g = GsonHelper.getGson (true, true);
        Object o = g.fromJson ("", String.class);
        System.out.println (o);
        Object o1 = g.fromJson ((String)null, String.class);
        System.out.println (o1);

/*
        URL url = new URL ("http://localhost:8080/dreamwork/api/v1.0/product/complexPost?storeId=123");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection ();
        conn.setRequestMethod ("POST");
        conn.setDoInput (true);
        conn.setDoOutput (true);

        Gson g = new Gson ();
        Person person = new Person ();
        person.setName ("seth.yang");
        person.setGender (Gender.Male);
        person.setAge (37);

        Map<String, Object> map = new HashMap<String, Object> ();
        map.put ("id", 1);
        map.put ("person", person);

        String text = g.toJson (map);
        OutputStream out = conn.getOutputStream ();
        out.write (text.getBytes ("utf-8"));
        out.flush ();

        InputStream in = conn.getInputStream ();
        ByteArrayOutputStream baos = new ByteArrayOutputStream ();
        byte[] buff = new byte[512];
        int length;
        while ((length = in.read (buff)) != -1)
            baos.write (buff, 0, length);
        System.out.println (baos.toString ("utf-8"));
*/
    }
}